<template>
  <div class="components-container">
    <div class="header-form">
     <div class="layui-inline">
        <label class="layui-form-label" >项目状态</label>
         <div class="layui-input-inline">
        <el-select v-model="selectData.chastatusEqual" placeholder="请选择项目状态">
          <el-option label="全部" :value="null"></el-option>
          <el-option v-for="item in chaStatusTypes" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
         </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label" >项目名称</label>
         <div class="layui-input-inline">
            <el-input  v-model="selectData.nameLike" placeholder="请输入辖区"></el-input>
         </div>
      </div>
      <el-button type="primary"  @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button  @click="btnRepeat">重置</el-button>
    </div>
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <chargeManageMain ref="sweetModalMain" :orderType="order" @refreshData="getData"></chargeManageMain>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import chargeManageMain from "./chargeManageMain";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";

const ADD = "新增";
const MODIFYPROJECT = "修改";
const MODIFYPRICE = "价格修改";
const DELETE = "删除";
const INFO = "详情";
const CKLSJG = "历史价格查询";

export default {
  name: "chargeProjectManage",
  mixins: [manage],
  data() {
    return {
      loading: false,
      chaStatusTypes: [],

      selectData: {},
      chaData: {},
      sweetModalWidth: 80,
      sweetModalMaxWidth: 840,
    };
  },
  methods: {
    //收费项目查询
    getData() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Cyp.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
   
    //分页和排序
    pageChange(value) {
      this.pageOrder = value;
      this.getData();
    },
   
    //获取收费项目状态
    getChaStatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.ChaStatus,
        res => {
          let cdhTypeData = res.data.content,
            legendsCdhData = cdhTypeData.map(item => ({
              label: item.Text,
              value: item.Value
            }));
          this.chaStatusTypes = legendsCdhData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getChargeProjectColumn() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetSfdlColumns,
        res => {
          this.headList = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.$refs.sweetModalMain.open(this.order);
          break;
        case MODIFYPROJECT:
        case INFO:
        case DELETE:
         this.$refs.sweetModalMain.open(this.order, this.currentRow);
          break;
        default:
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.CHASTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFYPROJECT:
        case MODIFYPRICE:
        case DELETE:
        case CKLSJG:
          return status !== '';
          break;
        case ORDER.END:
          return status === '正常';
          break;
        case ORDER.START:
          return status === '禁用';
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.chaData = {};
    },
   
  },
  components: {
    sweetModal,
    dataTable,
    chargeManageMain,
  },
  mounted() {},
  created() {
    this.getChargeProjectColumn();
    this.getData();
    this.getChaStatus();
  }
};
</script>
